package zj.it.bhne.huanxin.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;

import zj.it.bhne.huanxin.R;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText register_name;
    private EditText register_pass;
    private Button btn_register;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        context = this;
        initView();
    }

    private void initView() {
        register_name = (EditText) findViewById(R.id.register_name);
        register_pass = (EditText) findViewById(R.id.register_pass);
        btn_register = (Button) findViewById(R.id.btn_register);

        btn_register.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_register:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            EMClient.getInstance().createAccount(register_name.getText().toString().trim(), register_pass.getText().toString().trim());//同步方法
                            //HuanApplication.setShortToast(context,"注册成功");
                            startActivity(new Intent(context,MainActivity.class));
                            finish();
                        } catch (HyphenateException e) {
                            //HuanApplication.setShortToast(context,"注册失败");
                            e.printStackTrace();
                            Log.e("TAG", "onClick:2222222222 "+e.getDescription() );
                        }
                    }
                }).start();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

}
